package com.jprocms.module.cms.controller.admin.imgblockpic;

import com.jprocms.module.cms.util.CmsContextUtil;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.jpro.framework.common.pojo.PageParam;
import com.jpro.framework.common.pojo.PageResult;
import com.jpro.framework.common.pojo.CommonResult;
import com.jpro.framework.common.util.object.BeanUtils;
import static com.jpro.framework.common.pojo.CommonResult.success;

import com.jpro.framework.excel.core.util.ExcelUtils;

import com.jpro.framework.apilog.core.annotation.ApiAccessLog;
import static com.jpro.framework.apilog.core.enums.OperateTypeEnum.*;

import com.jprocms.module.cms.controller.admin.imgblockpic.vo.*;
import com.jprocms.module.cms.dal.dataobject.imgblockpic.ImgblockPicDO;
import com.jprocms.module.cms.service.imgblockpic.ImgblockPicService;

@Tag(name = "管理后台 - 飘窗图片")
@RestController
@RequestMapping("/cms/imgblock-pic")
@Validated
public class ImgblockPicController {

    @Resource
    private ImgblockPicService imgblockPicService;

    @PostMapping("/create")
    @Operation(summary = "创建飘窗图片")
    @PreAuthorize("@ss.hasPermission('cms:imgblockpic:update')")
    public CommonResult<Long> createImgblockPic(@Valid @RequestBody ImgblockPicSaveReqVO createReqVO) {
        createReqVO.setSiteId(CmsContextUtil.getCurrSiteId());
        return success(imgblockPicService.createImgblockPic(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新飘窗图片")
    @PreAuthorize("@ss.hasPermission('cms:imgblockpic:update')")
    public CommonResult<Boolean> updateImgblockPic(@Valid @RequestBody ImgblockPicSaveReqVO updateReqVO) {
        imgblockPicService.updateImgblockPic(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除飘窗图片")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('cms:imgblockpic:update')")
    public CommonResult<Boolean> deleteImgblockPic(@RequestParam("id") Long id) {
        imgblockPicService.deleteImgblockPic(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得飘窗图片")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('cms:imgblockpic:update')")
    public CommonResult<ImgblockPicRespVO> getImgblockPic(@RequestParam("id") Long id) {
        ImgblockPicDO imgblockPic = imgblockPicService.getImgblockPic(id);
        return success(BeanUtils.toBean(imgblockPic, ImgblockPicRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得飘窗图片分页")
    @PreAuthorize("@ss.hasPermission('cms:imgblockpic:update')")
    public CommonResult<PageResult<ImgblockPicRespVO>> getImgblockPicPage(@Valid ImgblockPicPageReqVO pageReqVO) {
        PageResult<ImgblockPicDO> pageResult = imgblockPicService.getImgblockPicPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ImgblockPicRespVO.class));
    }

}